package com.hly.tool.businessunit;


import com.hly.tool.constants.Constants;
import com.hly.tool.object.HDomainObject;
import com.matrixone.apps.domain.DomainObject;
import com.matrixone.apps.domain.util.MapList;
import matrix.db.Context;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/7/26 21:39
 * @description：
 */
public class BusinessUnit
{

    /**
     * 指定层级的父级业务单位
     *
     * @param context
     * @param obj
     * @param level
     * @return
     * @throws Exception
     */
    public static MapList getTopLevelUnit(Context context, DomainObject obj, short level) throws Exception
    {
        return HDomainObject.getRelatedLevelObjects(context, obj.getObjectId(context), Constants.type_BusinessUnit + "," + Constants.type_Company, Constants.rel_Member + "," + Constants.rel_Division, true, false, level, null, null);
    }

    /**
     * 指定层级的父级业务单位
     *
     * @param context  上下文
     * @param objectId id
     * @param level    层级
     * @return
     * @throws Exception
     */
    public static MapList getTopLevelUnit(Context context, String objectId, short level) throws Exception
    {
        return HDomainObject.getRelatedLevelObjects(context, objectId, Constants.type_BusinessUnit + "," + Constants.type_Company, Constants.rel_Member + "," + Constants.rel_Division, true, false, level, null, null);
    }


    /**
     * 获取所有层级的父级业务单位
     *
     * @param context
     * @param personObj
     * @return
     * @throws Exception
     */
    public static MapList getTopUnits(Context context, DomainObject personObj) throws Exception
    {
        return HDomainObject.getRelatedObjects(context, personObj.getObjectId(context), Constants.type_BusinessUnit + "," + Constants.type_Company, Constants.rel_Member + "," + Constants.rel_Division, true, false, (short) 0, null, null);
    }

    /**
     * 获取所有层级的父级业务单位
     *
     * @param context  上下文
     * @param objectId id
     * @return
     * @throws Exception
     */
    public static MapList getTopUnits(Context context, String objectId) throws Exception
    {
        return HDomainObject.getRelatedObjects(context, objectId, Constants.type_BusinessUnit + "," + Constants.type_Company, Constants.rel_Member + "," + Constants.rel_Division, true, false, (short) 0, null, null);
    }


    /**
     * 指定层级的子级 公司、业务单位、人员
     *
     * @param context
     * @param obj
     * @param level
     * @return
     * @throws Exception
     */
    public static MapList getSubLevelUnit(Context context, DomainObject obj, short level) throws Exception
    {
        return HDomainObject.getRelatedLevelObjects(context, obj.getObjectId(context), Constants.type_BusinessUnit + "," + Constants.type_Company + "," + Constants.type_Person, Constants.rel_Member + "," + Constants.rel_Division, false, true, level, null, null);
    }

    /**
     * 指定层级的子级 公司、业务单位、人员
     *
     * @param context  上下文
     * @param objectId id
     * @param level    层级
     * @return
     * @throws Exception
     */
    public static MapList getSubLevelUnit(Context context, String objectId, short level) throws Exception
    {
        return HDomainObject.getRelatedLevelObjects(context, objectId, Constants.type_BusinessUnit + "," + Constants.type_Company + "," + Constants.type_Person, Constants.rel_Member + "," + Constants.rel_Division, false, true, level, null, null);
    }


    /**
     * 获取所有子级 公司、业务单位、人员
     *
     * @param context
     * @param personObj
     * @return
     * @throws Exception
     */
    public static MapList getSubUnits(Context context, DomainObject personObj) throws Exception
    {
        return HDomainObject.getRelatedObjects(context, personObj.getObjectId(context), Constants.type_BusinessUnit + "," + Constants.type_Company + "," + Constants.type_Person, Constants.rel_Member + "," + Constants.rel_Division, false, true, (short) 0, null, null);
    }

    /**
     * 获取所有子级 公司、业务单位、人员
     *
     * @param context  上下文
     * @param objectId id
     * @return
     * @throws Exception
     */
    public static MapList getSubUnits(Context context, String objectId) throws Exception
    {
        return HDomainObject.getRelatedObjects(context, objectId, Constants.type_BusinessUnit + "," + Constants.type_Company + "," + Constants.type_Person, Constants.rel_Member + "," + Constants.rel_Division, false, true, (short) 0, null, null);
    }


}
